﻿//
// Copyright (c) 2024 BPer
//

#ifndef BPERUTIL_BUFFER_BPERBUFFER2_H_
#define BPERUTIL_BUFFER_BPERBUFFER2_H_
#include <bperutil/sys/BPerThread.h>
#include <bperutil/BPerType.h>
#include <bperutil/BPerAvType.h>
#define bPer_reindex2(p)  if(p!=NULL) p->resetIndex(&p->mediaBuffer);

typedef struct{
	int32_t mediaType;
	int32_t uid;
	uint32_t putIndex;
	uint32_t getIndex;
	uint32_t cache_num;
	uint32_t size;
	uint32_t nextIndex;
	int32_t ret;
	bPer_thread_mutex_t mlock;
	BPerFrame** frames;
	uint8_t* bufferManager;
}BPerMediaBufferSession2;

typedef struct{
	BPerMediaBufferSession2 session;
	void (*resetIndex)(BPerMediaBufferSession2* session);
	void (*initFrames)(BPerMediaBufferSession2* session,int pnum,int unitsize);

	void (*putFrame)(BPerMediaBufferSession2* session,BPerFrame* pframe);
	void (*getFrame)(BPerMediaBufferSession2* session,BPerFrame* pframe);
	BPerFrame* (*getCurFrameRef)(BPerMediaBufferSession2* session);
	int64_t (*getNextFrameTimestamp)(BPerMediaBufferSession2* session);
	uint8_t* (*getFrameRef)(BPerMediaBufferSession2* session,BPerFrame* pframe);


}BPerMediaBuffer2;

void bPer_create_mediaBuffer2(BPerMediaBuffer2* buf);
void bPer_destroy_mediaBuffer2(BPerMediaBuffer2* buf);

#endif /* BPERUTIL_BUFFER_BPERBUFFER_H_ */
